package com.example.asus.a222dzd_ordering.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.asus.a222dzd_ordering.R;
import com.example.asus.a222dzd_ordering.base.BaseListner;
import com.example.asus.a222dzd_ordering.base.BaseModel;
import com.example.asus.a222dzd_ordering.bean.RegisterBean;
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener{

    private EditText et_username,et_password,et_password2,et_phone,et_address;
    private Button bt_register;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        initView();
    }

    private void initView(){
        et_username = findViewById(R.id.et_username);
        et_password = findViewById(R.id.et_password);
        et_phone = findViewById(R.id.et_phone);
        bt_register = findViewById(R.id.bt_register);
        bt_register.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case(R.id.bt_register):
                String password=et_password.getText().toString();
                String username=et_username.getText().toString();
                String phone=et_phone.getText().toString();
                    BaseModel<RegisterBean> model = new BaseModel<>();
                    model.callEnqueue(model.service.register(username, password,phone), new BaseListner<RegisterBean>() {
                        @Override
                        public void onResponse(RegisterBean bean) {
                            if (bean.getSuccess().equals("0"))
                                Toast.makeText(getApplicationContext(), "注册失败", Toast.LENGTH_SHORT).show();
                            else {
                                Toast.makeText(getApplicationContext(), "注册成功:" , Toast.LENGTH_SHORT).show();
                                finish();
                            }
                        }

                        @Override
                        public void onFail(String msg) {
                            Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT).show();
                        }
                    });
                break;
        }
    }
}
